//               https://ac.nowcoder.com/acm/problem/221822





#include <iostream>
using namespace std;

const int N = 1e6 + 10;
int f[N];

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;

    f[1] = s[0];
    int len = 1;
    for (int i = 1; i < n; i++)
    {
        if (f[len] <= s[i])
            f[++len] = s[i];
        else
        {
            int l = 1, r = len;
            while (l < r)
            {
                int mid = l + r >> 1;
                if (s[i] < f[mid])
                    r = mid;
                else
                    l = mid + 1;
            }
            f[l] = s[i];
        }
    }
    cout << n - len;
    return 0;
}
